package cc.ufinity.networkdiagnose.view;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.MenuItem;

public class AbstractActivity extends Activity {
	
	protected void exit() {
		android.os.Process.killProcess(android.os.Process.myPid());
	}

	private void showDialog() {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setTitle("提示");
		builder.setIcon(R.drawable.what);
		builder.setMessage("确定退出系统吗？");
		builder.setCancelable(false);
		builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				exit();
			}
		});
		builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				dialog.cancel();
			}
		});
		builder.show();
	}
	
	// *添加菜单
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
	//	menu.add(0, 0, 0, "").setIcon(R.drawable.xml_main_exit);
		menu.add(0, 0, 0, "退    出");

		return super.onCreateOptionsMenu(menu);
	}

	// *管理菜单项
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		if (item.getItemId() == 0) {
			showDialog();
		}

		return super.onOptionsItemSelected(item);
	}
}
